<script>
const app = require('./utils/app.js').default;
const $ = require('./utils/api.js');
let appRole = 'demo';
export default {
	globalData: {
		appRole: appRole, 
		name: app[appRole]['name'],
		version: app[appRole]['version'],
		api: app[appRole]['api'], 
		hot: app[appRole]['hot'],
		socket: app[appRole]['socket'] ? app[appRole]['socket'] : '',
		mapKey: 'ML5BZ-G4JKK-ZUIJN-ACWR7-7TQXV-HBBEC',
		height: 0,
		tuijianren: '',
		isWeiXin: false,
	},
	onLaunch: function(options) {
		// var vConsole = new VConsole();
		const self = this;
		this.globalData.tuijianren = options.query.invite ? options.query.invite : '';
		uni.getSystemInfo({
			success: function(res) {
				// console.log(res);
				self.globalData.height = res.windowHeight;
				if (res.platform == 'devtools') {
					let nav_top = Number(res.statusBarHeight);
					uni.setStorageSync('bartop', nav_top);
				} else if (res.platform == 'ios') {
					let nav_top = Number(res.statusBarHeight);
					uni.setStorageSync('bartop', nav_top);
					uni.setStorageSync('isIos', true);
				} else if (res.platform == 'android') {
					let nav_top = Number(res.statusBarHeight);
					uni.setStorageSync('bartop', nav_top);
					uni.setStorageSync('isIos', false);
				}
				let safeArea = ['iPhone8','iPhone8Pro','iPhone7','iPhone7Pro','iPhone6','iPhone6Pro','iPhone5','iPhoneSE'];
				if(res.platform == 'ios') {
					// #ifndef H5
					uni.setStorageSync('isIphonex', true);
					// #endif
					safeArea.forEach((ele,index) => {
						if(res.model && res.model.indexOf(ele) >= 0) {
							uni.setStorageSync('isIphonex', false);
						}
					})
				}
				uni.setStorageSync('model', res.model);
			}
		});
	},

	methods: {
		h5Reload() {
			var url = window.location.href; //页面url
			var beforeUrl = url.substr(0, url.indexOf("?"));
			var afterUrl = url.substr(url.indexOf("#"));
			window.location.replace(beforeUrl + afterUrl);
		},
		 isWeiXin(){
		    var ua = window.navigator.userAgent.toLowerCase();
		    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
				this.globalData.isWeiXin = true;
		        return true;
		    }else{
		        return false;
		    }  
		},
	},
	onShow: function() {
		
	},
	onHide: function() {
		console.log('App Hide');
	}
};
</script>

<style>
@import './static/css/uni.css';
@import './static/css/color.css';
@import './static/css/common.css';
/* 解决头条小程序组件内引入字体不生效的问题 */
/* #ifdef MP-TOUTIAO */
@font-face {
	font-family: uniicons;
	src: url('/static/uni.ttf');
}
/* #endif */
</style>
